<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class GoodsClassify extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $exists = $this->hasTable('goods_classify');
        if (!$exists) {
            $table = $this->table('goods_classify', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_unicode_ci', 'comment' => '商品分类', 'id' => 'id', 'signed' => true, 'primary_key' => ['id']]);
            $table->addColumn('classify_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => true,'signed' => true,'comment' => '分类ID',])
                ->addColumn('img', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '背景图',])
                ->addColumn('name', 'string', ['limit' => 50, 'null' => false, 'default' => null, 'signed' => true, 'comment' => '名称',])
                ->addColumn('weigh', 'integer', ['limit' => MysqlAdapter::INT_REGULAR, 'null' => false, 'default' => 0, 'signed' => true, 'comment' => '权重',])
                ->addColumn('status', 'boolean', ['null' => false, 'default' => 1, 'signed' => true, 'comment' => '状态：1 正常（首页推送）、2 正常、3 隐藏',])
                ->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_BIG, 'null' => true, 'signed' => true, 'comment' => '创建时间',])
                ->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_BIG, 'null' => true, 'signed' => true, 'comment' => '更新时间',])
                ->create();
        }
    }
}
